package org.rowan.infovis.soccer;

import com.sun.opengl.util.GLUT;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;

public class MechanicsPlot {

    private GLUT glut;
    private int fluency;
    private int coordination;
    private int easiness;
    private int rapidity;
    private int radius = 120;

    public MechanicsPlot(int fluency, int coordination, int easiness, int rapidity) {
        this.glut = new GLUT();
        this.fluency = fluency;
        this.coordination = coordination;
        this.easiness = easiness;
        this.rapidity = rapidity;
    }

    public void draw(GL gl) {
        drawCenterCircle(gl);
        drawFluency(gl);
        drawCoordination(gl);
        drawEasiness(gl);
        drawRapdity(gl);
        gl.glColor3f(0f, 0f, 0f);
        drawDot(gl);
        drawRings(gl);
        drawTitles(gl);
    }
    
    private void drawDot(GL gl) {
        int dot_radius = 8;
        GLU glu = new GLU();
        GLUquadric dot = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(dot, GLU.GLU_FILL);
        glu.gluDisk(dot, 0, dot_radius, 60, 60);
    }

    private void drawCenterCircle(GL gl) {
        gl.glColor3f(0f, 0f, 0f);

        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, 0, radius + 5, 60, 60);
    }

    private void drawRings(GL gl) {
        gl.glColor3f(0f, 0f, 0f);

        for (radius = 120; radius >= 30; radius -= 30) {
            GLU glu = new GLU();
            GLUquadric circle = glu.gluNewQuadric();
            circle = glu.gluNewQuadric();
            glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
            glu.gluDisk(circle, radius - 1, radius, 60, 60);
        }
    }

    private void drawFluency(GL gl) {
        setColor(gl, fluency);
        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, 0, 120, 60, 60);
    }

    private void drawCoordination(GL gl) {
        setColor(gl, coordination);
        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, 0, 90, 60, 60);
    }

    private void drawEasiness(GL gl) {
        setColor(gl, easiness);
        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, 0, 60, 60, 60);
    }

    private void drawRapdity(GL gl) {
        setColor(gl, rapidity);
        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, 0, 30, 60, 60);
    }

    private void drawAxis(GL gl) {
        gl.glBegin(GL.GL_LINES);
        gl.glColor3f(0f, 0f, 0f);
        gl.glVertex2d(0, 0);
        gl.glVertex2d(0, radius);
        gl.glEnd();
    }

    private void setColor(GL gl, int likert) {
        switch (likert) {
            case 1:
                gl.glColor3f(1f, 0f, 0f);
                break;
            case 2:
                gl.glColor3f(1f, 0.563f, 0f);
                break;
            case 3:
                gl.glColor3f(1f, 1f, 0f);
                break;
            case 4:
                gl.glColor3f(0f, 1f, 0f);
                break;
            default:
                break;
        }
    }

    private void drawTitles(GL gl) {
        gl.glColor3f(0f,0f,0f);
        
        gl.glPushMatrix();
            gl.glRasterPos2f(-27f,100f);
            glut.glutBitmapString(GLUT.BITMAP_8_BY_13, "Fluency");
        gl.glPopMatrix();
        
        gl.glPushMatrix();
            gl.glRasterPos2f(-45f,65f);
            glut.glutBitmapString(GLUT.BITMAP_8_BY_13, "Coordination");
        gl.glPopMatrix();

        gl.glPushMatrix();
            gl.glRasterPos2f(-30f,37f);
            glut.glutBitmapString(GLUT.BITMAP_8_BY_13, "Easiness");
        gl.glPopMatrix();

        gl.glPushMatrix();
            gl.glRasterPos2f(-30f,10f);
            glut.glutBitmapString(GLUT.BITMAP_8_BY_13, "Rapidity");
        gl.glPopMatrix();
    }
}
